// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

var plane_mgr = require('plane_mgr')
var bullet_mgr = require('bullet_mgr')

cc.Class({
    extends: cc.Component,

    properties: {
        isPlaying: false,
        mask: {
            type: cc.Node,
            default: null
        },
        plane: {
            type: plane_mgr,
            default: null
        },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.on_touch_start, this)
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.on_touch_move, this)
        this.node.on(cc.Node.EventType.TOUCH_END, this.on_touch_end, this)
    },

    on_touch_start () {
        console.log('on_touch_start')
        this.isPlaying = true
        this.mask.stopAllActions()
        this.mask.runAction(cc.fadeOut(0.5))

        this.plane.enterFireMode()
    },
    on_touch_move (event) {
        console.log('on_touch_move')
        var offset = event.getDelta()
        this.plane.doMove(offset, this.node)
    },
    on_touch_end () {
        console.log('on_touch_end')
        this.isPlaying = false
        this.mask.stopAllActions()
        this.mask.runAction(cc.fadeIn(0.5))

        
        this.plane.leaveFireMode()
    },
    // update (dt) {},
});
